package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import com.zzyl.vo.RoomTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public void addBed(BedDto bedDto) {
        Bed bed = BeanUtil.toBean(bedDto, Bed.class);
        bed.setBedStatus(0);
        bed.setCreateTime(LocalDateTime.now());
        bed.setUpdateTime(LocalDateTime.now());
        bed.setCreateBy(1L);
        bed.setUpdateBy(1L);
        bedMapper.addBed(bed);
    }

    @Override
    public BedVo findBedById(Long id) {
        Bed bed = bedMapper.getBedById(id);
        return BeanUtil.toBean(bed, BedVo.class);
    }

    @Override
    public void modifyBed(BedDto bedDto) {
        Bed bed = bedMapper.getBedById(bedDto.getId());
        if (bed==null){
            throw new BaseException(BasicEnum.DATA_NOT_EXITS);
        }
        bed.setBedNumber(bedDto.getBedNumber());
        bed.setSort(bedDto.getSort());
        bed.setUpdateTime(LocalDateTime.now());
        bed.setUpdateBy(1L);
        bedMapper.modifyBed(bed);
    }

    @Override
    public void removeBed(Long id) {
        bedMapper.removeBed(id);
    }
}
